<?php
/**
 * Patient Signal form 1. Used in create and update action in PatientSignalController.
 *
 * @package   views
 * @subpackage patientSignal
 * @since     1.0
 * @filesource
 */
?>
	<div class="row">
		<?php echo $form->labelEx($model,'subject'); ?>
		<?php echo $form->textField($model,'subject'); ?>
		<?php echo $form->error($model,'subject'); ?>
	</div>
	<div class="row span-5">
		<?php echo $form->labelEx($model,'dateOfBirth'); ?>
		<?php echo $form->hiddenField($model,'dateOfBirth'); ?>
		<?php
		$this->widget('zii.widgets.jui.CJuiDatePicker', array(
	    	'name'=>'dobSelect',
	    	'options'=>array(
				'altField'=>'#'.CHtml::activeId($model, "dateOfBirth"),
				'dateFormat' =>'yy-mm',
				'altFormat'=>'yy-mm-01',
				'onSelect'=>'js:function(dateText,inst){
					var birthDate = new Date(dateText).getTime();
					var today = new Date().getTime();
					if (isNaN(birthDate)){
						// the parsing does not work in some browsers
						var dateParts = dateText.split("-");
						birthDate = new Date(dateParts[0], (dateParts[1] - 1) ,dateParts[1]).getTime();
					}
					var diffDate = Math.round((today-birthDate)/86400000);					
					var monthLength = 365.25/12;
					var diffMonth = Math.floor(diffDate/monthLength);
					var diffYear = Math.floor(diffMonth/12);
					diffMonth %=12;
					$("#'.CHtml::activeId($model, "ageYear").'").val(diffYear);
					$("#'.CHtml::activeId($model, "ageMonth").'").val(diffMonth);
				}',
	    	),
	    	'value'=>$model->dateOfBirth?substr($model->dateOfBirth, 0,7):'',
		));
		?>
		<?php echo $form->error($model,'dateOfBirth'); ?>
	</div>
	<div class="row span-5">
		<?php echo CHtml::label('Age', Chtml::activeId($model, 'ageYear'),array('required'=>true));?>
		<?php echo $form->textField($model,'ageYear',array('style'=>'width: 40px;')); ?> Years <?php 
		echo $form->dropDownList($model,'ageMonth',DataUtil::getNumers(11),array('empty'=>'','style'=>'width: 40px;')); ?> Months
		<?php echo $form->error($model,'ageYear'); ?>
		<?php echo $form->error($model,'ageMonth'); ?>
	</div>
	<div class="row span-5">
		<?php echo $form->labelEx($model,'gender'); ?>
		<?php echo $form->dropDownList($model,'gender',DataUtil::getGenders(),array('empty'=>'Please select')); ?>
		<?php echo $form->error($model,'gender'); ?>
	</div>
	
	<div class="clear"></div>
	<span class="hint">The day of subject's birth date will not be stored in system.</span>
	<div class="clear"></div>

	<div class="row span-5">
		<?php echo $form->labelEx($model,'disorderId'); ?>
		<?php echo $form->dropDownList($model,'disorderId',
			Yii::app()->user->checkAccess('admin') ? Disorder::model()->getAllDisorders(): Disorder::model()->getAllActiveDisorders(),
			array('empty'=>'Please select')); ?>
		<?php echo $form->error($model,'disorderId'); ?>
	</div>

	<div class="row span-5">
		<?php echo $form->labelEx($model,'severity'); ?>
		<?php echo $form->textField($model,'severity'); ?>
		<?php echo $form->error($model,'severity'); ?>
	</div>

	<div class="row span-5">
		<?php echo $form->labelEx($model,'recordingTime'); ?>
		<?php 
		$this->widget('ext.timepicker.EJuiDateTimePicker',array(
		    'model'=>$model,
		    'attribute'=>'recordingTime',
		    ));  
		?>
		<?php echo $form->error($model,'recordingTime'); ?>
	</div>
	<div class="clear"></div>
	<div class="row">
		<?php echo $form->labelEx($model,'pastDiagnosticHistory'); ?>
		<?php echo $form->textArea($model,'pastDiagnosticHistory',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'pastDiagnosticHistory'); ?>
	</div>